<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>15 斐波那契数列</title>
</head>

<body>
    <h1>15 斐波那契数列</h1>
</body>
<script>
    /*
        斐波那契数列(兔子数列)
            月份: 1 2 3 4 5 6 7 8 9 10
            兔子（对数）：1 1 2 3 5 8 13 21 34 55
        
        规律：第三个月起，每个月的数量是前两月之和
        fac(n) = fac(n-1) + fac(n-2)
        n >= 3
        n <= 2  fac(n) == 1

    */

    // 递归函数实现斐波那契数列

    function fac(n) {
        if (n <= 2) {
            return 1
        }
        return fac(n - 1) + fac(n - 2);
    }

    var res = fac(10);
    console.log(res);
</script>

</html>